var express = require('express');
var path = require('path');
var upload = require('./routes/upload');

var app = express();

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use('/', upload);
app.use('/static', express.static(path.join(__dirname, 'public')));

const port = process.env.port || 3000; //对应一个端口号

///获取本机ip///
const os = require('os');

function getIPAdress() {
	var interfaces = os.networkInterfaces();
	for (var devName in interfaces) {
		var iface = interfaces[devName];
		for (var i = 0; i < iface.length; i++) {
			var alias = iface[i];
			if (
				alias.family === 'IPv4' &&
				alias.address !== '127.0.0.1' &&
				!alias.internal
			) {
				return alias.address;
			}
		}
	}
}
const myHost = getIPAdress();

app.listen(port, () => {
	console.log(`项目启动地址：http://${myHost}:${port}`);
});
